package net.aiion.weave.impl.cards.expressions;

import java.util.HashMap;
import java.util.Map;

import net.aiion.weave.spi.cards.expressions.CardExpression;
import net.aiion.weave.spi.cards.expressions.CardExpressionResolver;

public class CardVariableExpressionResolver implements CardExpressionResolver
{
    private static final String VARIABLE_PREFIX = "variable";

    private final Map<String, Object> variables;

    public CardVariableExpressionResolver() {
        variables = new HashMap<>();
    }

    @Override
    public boolean resolvesExpression(final CardExpression aCardExpression) {
        return VARIABLE_PREFIX.equals(aCardExpression.getPrefix());
    }

    @Override
    public Object readExpression(final CardExpression aCardExpression) {
        return variables.get(aCardExpression.getValue());
    }

    @Override
    public void writeExpression(final CardExpression aCardExpression, final Object aValue) {
        variables.put(aCardExpression.getValue(), aValue);
    }
}
